import { createAsyncThunk } from '@reduxjs/toolkit';
import axios, { AxiosError } from 'axios';
import { API } from '../../helpers/API';

export const fetchBallsSlice = createAsyncThunk(
	'balls/fetchBallsSlice',
	async () => {
		try {
			const { data } = await axios.get(`${API}/balls`);
			return data;
		} catch (error) {
			if (error instanceof AxiosError) {
				throw new Error(error.response?.data.message);
			}
		}
	}
);
